package com.jvtd.nettyim.im.client.console;

import com.jvtd.nettyim.im.protocol.request.LoginRequestPacket;
import io.netty.channel.Channel;

import java.util.Scanner;
import java.util.concurrent.TimeUnit;

/**
 * @author Created by neal.zhang
 * @date 2020/6/1 - 11:56
 */
public class LoginConsoleCommand implements ConsoleCommand{
    @Override
    public void exec(Scanner scanner, Channel channel) {
        LoginRequestPacket loginRequestPacket = new LoginRequestPacket();
        System.err.print("userName :");
        loginRequestPacket.setUserName(scanner.next());
        loginRequestPacket.setPassword("psw");
        channel.writeAndFlush(loginRequestPacket);
        waitForLoginResponse();
    }

    /**
     *
     */
    private void waitForLoginResponse() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
